package com.thfw.test.model.bean;

/**
 * Created BY Cuishikun
 * Created ON 2022/2/17
 * Package Name com.thfw.test.model.bean
 **/

import android.content.Context;
import android.net.wifi.ScanResult;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.thfw.test.view.adapter.BlueToothAdapter;
import com.thfw.wmd.R;
import com.thfw.test.view.model.BluetoothLeDevice;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created BY Cuishikun
 * Created ON 2021/9/13
 * Package Name com.thfw.test.view.adapter
 **/
//自定义的适配器
public class GroupAdapter extends BaseAdapter {
    private List<GroupBean> mlist;
    private Map<String,Light> map;
    private Context mContext;
    private boolean isShowCheckBox;
    private String groupId = "-3";
    private boolean onlyShowGroup;
    OnItemCallBack itemCallBack;

    public GroupAdapter(Context context, List<GroupBean> list,Map<String,Light> map) {
        this.mContext = context;
        mlist = new ArrayList<GroupBean>();
        this.mlist = list;
        this.map = map ;
    }


    @Override
    public int getCount() {
        return mlist.size();
    }


    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setListAll(List<GroupBean> list) {
        if (mlist == null) {
            mlist = new ArrayList<>();
        }
        mlist.clear();
        mlist.addAll(list);
        notifyDataSetChanged();
    }

    public void clear() {
        if (mlist != null) mlist.clear();
        notifyDataSetChanged();
    }

    public void setOnClickMyTextView(OnItemCallBack itemCallBack) {
        this.itemCallBack = itemCallBack;
    }
    Light person = null;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(R.layout.group_item, null);
            person = new Light();
            person.rl_group_all = (RelativeLayout) convertView.findViewById(R.id.rl_group_all);
            person.tv_group = (TextView) convertView.findViewById(R.id.tv_group);

            convertView.setTag(person);
        } else {
            person = (Light) convertView.getTag();
        }
        //赋值操作
//        person.name.setText(mlist.get(position).toString());
        person.tv_group.setText(mlist.get(position).getGroupName());
        Light finalPerson = person;
        person.rl_group_all.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemCallBack.onSelectedCallBack(position,true);
                itemCallBack.onSelectedDataCallBack(finalPerson);
            }
        });
        if (groupId.equals(mlist.get(position).getGroupId())) {
            person.rl_group_all.setSelected(true);
        } else {
            person.rl_group_all.setSelected(false);
        }

        return convertView;
    }


    public void setIconSelected(String groupId) {
        this.groupId = groupId;
        notifyDataSetChanged();
    }

    public String getSelectedGroupId() {
        if(groupId!=null && !groupId.equals("")){
            return groupId;
        }else{
            return "-3";
        }
    }

    public static class Light {
        RelativeLayout rl_group_all;
        TextView tv_group;
        int cxsjGroup =5 ;
        int jbsjGroup = 5;
        int groupDown = 1;

        public int getCxsjGroup() {
            return cxsjGroup;
        }

        public void setCxsjGroup(int cxsjGroup) {
            this.cxsjGroup = cxsjGroup;
        }

        public int getJbsjGroup() {
            return jbsjGroup;
        }

        public void setJbsjGroup(int jbsjGroup) {
            this.jbsjGroup = jbsjGroup;
        }

        public int getGroupDown() {
            return groupDown;
        }

        public void setGroupDown(int groupDown) {
            this.groupDown = groupDown;
        }

        public int getGroupUp() {
            return groupUp;
        }

        public void setGroupUp(int groupUp) {
            this.groupUp = groupUp;
        }

        public int getGroupProgress() {
            return groupProgress;
        }

        public void setGroupProgress(int groupProgress) {
            this.groupProgress = groupProgress;
        }

        public String getGroup1TimeOpenHour() {
            return group1TimeOpenHour;
        }

        public void setGroup1TimeOpenHour(String group1TimeOpenHour) {
            this.group1TimeOpenHour = group1TimeOpenHour;
        }

        public String getGroup1TimeOpenMin() {
            return group1TimeOpenMin;
        }

        public void setGroup1TimeOpenMin(String group1TimeOpenMin) {
            this.group1TimeOpenMin = group1TimeOpenMin;
        }

        public String getGroup1TimeCloseHour() {
            return group1TimeCloseHour;
        }

        public void setGroup1TimeCloseHour(String group1TimeCloseHour) {
            this.group1TimeCloseHour = group1TimeCloseHour;
        }

        public String getGroup1TimeCloseMin() {
            return group1TimeCloseMin;
        }

        public void setGroup1TimeCloseMin(String group1TimeCloseMin) {
            this.group1TimeCloseMin = group1TimeCloseMin;
        }

        public String getGroup1TimeClose() {
            return group1TimeClose;
        }

        public void setGroup1TimeClose(String group1TimeClose) {
            this.group1TimeClose = group1TimeClose;
        }

        int groupUp =1 ;
        int groupProgress =100;
        String group1TimeOpenHour = "00";
        String group1TimeOpenMin = "00";
        String group1TimeCloseHour = "00";
        String group1TimeCloseMin = "00";
        String group1TimeClose = "00";

    }

}